package com.hutianao.gqgl.organ.control;

import com.hutianao.gqgl.mybatis.entity.PtOrganEntity;
import com.hutianao.gqgl.mybatis.flexigrid.PaddingEntity;
import com.hutianao.gqgl.mybatis.flexigrid.PadingRstType;
import com.hutianao.gqgl.organ.entity.OrganBindEntity;
import com.hutianao.gqgl.organ.entity.SearchOrganEntity;
import com.hutianao.gqgl.organ.entity.SearchResultEntity;
import com.hutianao.gqgl.organ.service.OrganService;
import com.hutianao.gqgl.spring.control.BaseController;
import javax.annotation.Resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/organinfo")
public class OrganController extends BaseController {

    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private OrganService organService;

    @RequestMapping("/page")
    private String organPage(){
        return "organ/organPage";
    }

    @Secured("ROLE_gqgy_data_role_add")
    @RequestMapping("/addOrganInfo")
    @ResponseBody
    public String addOrganInfo(PtOrganEntity ptOrganEntity){
        logger.info(ptOrganEntity);

        return jsonSuccess( organService.addOrganInfo(ptOrganEntity));
    }

    @Secured("ROLE_gqgy_data_role_add")
    @RequestMapping("/updateOrganInfo")
    @ResponseBody
    public String updateOrganInfo(PtOrganEntity ptOrganEntity){
        logger.info(ptOrganEntity);

        return jsonSuccess( organService.updateOrganInfo(ptOrganEntity));
    }

    @RequestMapping("/getAllOrgan")
    @ResponseBody
    public String getAllOrgan(){
        return organService.getAllOrgan();
    }


    @RequestMapping("/queryOrganListById")
    @ResponseBody
    public PtOrganEntity queryOrganListById(@RequestParam("organUuid") String organUuid){
        return organService.queryOrganListById(organUuid);
    }

    @RequestMapping("/deleteOrganInfoByMenuId")
    @ResponseBody
    public String deleteOrganInfoByMenuId(PtOrganEntity ptOrganEntity){
        return jsonSuccess(organService.deleteOrganInfoByMenuId(ptOrganEntity.getOrganUuid()));
    }


    @RequestMapping("/queryOrganInfoListByPage")
    @ResponseBody
    public PadingRstType<SearchResultEntity> queryOrganInfoListByPage(SearchOrganEntity search, PaddingEntity padding){
        logger.info(search);
        logger.info(padding);
        PadingRstType<SearchResultEntity> padingRstType = organService.queryOrganInfoListByPage(search,padding);

        return padingRstType;
    }

    @Secured("ROLE_gqgy_data_role_add")
    @RequestMapping("/organBind")
    @ResponseBody
    public String organBind(OrganBindEntity organBindEntity){
        logger.info(organBindEntity);
        String result = organService.organBind(organBindEntity);
        return jsonSuccess(result);
    }


    @Secured("ROLE_gqgy_data_role_add")
    @RequestMapping("/organUpdate")
    @ResponseBody
    public String organUpdate(OrganBindEntity organBindEntity){
        logger.info(organBindEntity);
        String result = organService.organUpdate(organBindEntity);
        return jsonSuccess(result);
    }

    @Secured("ROLE_gqgy_data_role_add")
    @RequestMapping("/unBoundOrgan")
    @ResponseBody
    public String unBoundOrgan(PtOrganEntity ptOrganEntity){
        logger.info(ptOrganEntity);
        String result = organService.organUnBound(ptOrganEntity);
        return jsonSuccess(result);
    }

    @Secured("ROLE_gqgy_data_role_delete")
    @RequestMapping("/deleteOrganById")
    @ResponseBody
    public String deleteOrganById(@RequestParam("organUuidArray") String organUuidArray){
        logger.info("organUuidArray:" + organUuidArray);
        return jsonSuccess( organService.deleteOrganById(organUuidArray));
    }


    //    alan
    @RequestMapping("/updateMenuInfo")
    @ResponseBody
    public String updateOrganBInfo(PtOrganEntity ptOrganEntity){
        logger.info("ptMenuEntity:" + ptOrganEntity );
        organService.updateDictionaryInfo(ptOrganEntity);
        return jsonSuccess("menu.update.success");
    }
//    alan
    @RequestMapping("/deleteDictionaryInfoByDictionaryId")
    @ResponseBody
    public String deleteDictionaryInfoByDictionaryId(@RequestParam("dictId")String dictId){
        logger.info("dictId:" + dictId );
        organService.deleteDictionaryInfoByDictionaryId(dictId);
        return  jsonSuccess("dictionary.delete.success");

}
}
